﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Components;
using UI.ParentForm;
using Controls;

namespace UI.SellOrder
{
    public partial class Ord9a00Edit : UI.ParentForm.BaseEdit
    {
        public Ord9a00Edit(string action, string text, string key)
            : base(action)
        {
            InitializeComponent();

            this.Text = text;
            this.key = key;
            //回写的方法
            this.SaveCallFuntion = "Ord9a00Manager$SaveEditData"; //保存的方法

            this.Size = base.MaxWindow;

            LoadData();
        }

        //加载修改数据
        private void LoadData()
        {
            base.LoadEditData(null, string.Format(" a.listid ='{0}' ", this.key));
        }


        protected override void AfterSummaryCreateControl(string colName, Control c, Controls.Args.SummaryArgs e)
        {
            if ("price" == colName || "qty" == colName) //价格或者数量改变时，自动计算总金额
            {
                PsTextBox box = c as PsTextBox;
                if(null == box) return;

                box.ValueChanged += new TextBoxX.DgValueChanged(box_ValueChanged);
            }    
        }

        void box_ValueChanged(object sender, EventArgs e)
        {
            double price = Validation.ToDouble(this.tbSummary.GetValue("price"));
            double qty = Validation.ToDouble(this.tbSummary.GetValue("qty"));

            this.tbSummary.SetValue("amt", Validation.ToDouble(price * qty, 3));
        }
    }
}